import mysql.connector
import openpyxl

# mydb = mysql.connector.connect(
#     host="172.32.148.68",  # 数据库主机地址
#     user="hebeitower",  # 数据库用户名
#     port=3306,
#     database="hebei-tower",  # 数据库名称 没有的话插入操作报错
#     passwd="Hebeitower1!",  # 数据库密码
# )

# mydb = mysql.connector.connect(
#     host="121.36.64.108",  # 数据库主机地址
#     user="hebei",  # 数据库用户名
#     port=8181,
#     database="hebei-tower",  # 数据库名称 没有的话插入操作报错
#     passwd="Hebeitower1!",  # 数据库密码
# )

# 根据配置信息生成操作对象
mycursor = mydb.cursor()
# 定义要执行的sql %s为占位符
sql = "INSERT INTO hb_ai_pre (scene_type,package_name,file_name,relative_path,pre_table_id,pre_file_id) VALUES (%s,%s,%s,%s,%s,%s)"
#sql = "INSERT INTO hb_ai_pre_table (pre_table_id,table_name,cols) VALUES (%s,%s,%s)"

# workbook = openpyxl.load_workbook('hebei_dict_insert.xlsx')
workbook = openpyxl.load_workbook('hebei_ai_pre.xlsx')

sheet = workbook["hb_ai_pre"]
#sheet = workbook["hb_ai_pre_table"]

count = 0
for one_column_data in sheet.iter_rows():
    if count == 0:
        count = count + 1
        continue
    row_data = []
    for cell in one_column_data:
        row_data.append(cell.value)
        # print(cell.value)
    val = tuple(row_data)
    try:
        print(sql)
        mycursor.execute(sql, val)
        mydb.commit()
    except :
        print("出错")
    print(val)
